
################################################################################
# Predictive validity: Three-Way Interactions (Meta) 
################################################################################

# 1. Activism =====================================================================
# Interaction model
Mactiv<-lm(activism ~ 
             age + education_num + sex_fem  + ideology + # demographics
             Analysis+
             InterestedNum+
             InterestedNum*pos_id_mean*neg_id_mean , # 3 way interaction
           data = meta_std) # data frame with only interested 

# Create interaction data frame
inter_activ <- emmip(Mactiv,neg_id_mean~pos_id_mean~InterestedNum,at=list, CIs=TRUE, PIs=TRUE, plotit = FALSE)
inter_activ$combination<-paste(inter_activ$xvar,inter_activ$tvar, sep = " ") # combine conditions

inter_activ_keep<-inter_activ%>% 
  mutate(DV = "Political activism (H1)") %>% # add new colomn for DV
  dplyr::select(., combination,yvar, LCL, UCL, DV)%>% 
  rename(EMM = yvar, CI_lower = LCL, CI_upper = UCL)%>%
  pivot_wider(names_from = "combination", values_from = "EMM")

# 2. News Consumption =============================================================
# Interaction model
Mnews<-lm(pol_news_con ~ 
            age + education_num + sex_fem  + ideology + # demographics
            Analysis+
            InterestedNum+
            InterestedNum*pos_id_mean*neg_id_mean , # 3 way interaction
          data = meta_std) # data frame with only interested 

# Create interaction data frame
inter_news <- emmip(Mnews,neg_id_mean~pos_id_mean~InterestedNum,at=list, CIs=TRUE, PIs=TRUE, plotit = FALSE)
inter_news$combination<-paste(inter_news$xvar,inter_news$tvar, sep = " ") # combine conditions

inter_news_keep<-inter_news%>% 
  mutate(DV = "News consumption (H2b)") %>%
  dplyr::select(., combination,yvar, LCL, UCL, DV)%>% 
  rename(EMM = yvar, CI_lower = LCL, CI_upper = UCL)%>%
  pivot_wider(names_from = "combination", values_from = "EMM")


# 3. News openness ===============================================================
# Interaction model
Mopen<-lm(news_openness ~ 
             age + education_num + sex_fem  + ideology + # demographics
             Analysis+
             InterestedNum+
             InterestedNum*pos_id_mean*neg_id_mean , # 3 way interaction
           data = meta_std) # data frame with only interested 

# Create interaction data frame
inter_open <- emmip(Mopen,neg_id_mean~pos_id_mean~InterestedNum,at=list, CIs=TRUE, PIs=TRUE, plotit = FALSE)
inter_open$combination<-paste(inter_open$xvar,inter_open$tvar, sep = " ") # combine conditions

#inter_open_keep<-inter_open%>%
#  dplyr::select(., combination,yvar)%>%
#  pivot_wider(names_from = "combination", values_from = "yvar")
#inter_open_keep$DV<- "News openness (H4b; H4d)"

inter_open_keep<-inter_open%>% 
  mutate(DV = "News openness (H4b; H4d)") %>%
  dplyr::select(., combination,yvar, LCL, UCL, DV)%>% 
  rename(EMM = yvar, CI_lower = LCL, CI_upper = UCL)%>%
  pivot_wider(names_from = "combination", values_from = "EMM")


# 4. Political Efficacy ==========================================================
# Interaction model
Meff<-lm(pol_efficacy ~ 
           age + education_num + sex_fem  + ideology + # demographics
           Analysis+
           InterestedNum+
           InterestedNum*pos_id_mean*neg_id_mean , # 3 way interaction
         data = meta_std) # data frame with only interested 

# Create interaction data frame
inter_eff <- emmip(Meff,neg_id_mean~pos_id_mean~InterestedNum,at=list, CIs=TRUE, PIs=TRUE, plotit = FALSE)
inter_eff$combination<-paste(inter_eff$xvar,inter_eff$tvar, sep = " ") # combine conditions

#inter_eff_keep<-inter_eff%>%
#  dplyr::select(., combination,yvar)%>%
#  pivot_wider(names_from = "combination", values_from = "yvar")
#inter_eff_keep$DV<- "Political efficacy (H2a; H3)"

inter_eff_keep<-inter_eff%>% 
  mutate(DV = "Political efficacy (H2a; H3)") %>%
  dplyr::select(., combination,yvar, LCL, UCL,DV )%>% 
  rename(EMM = yvar, CI_lower = LCL, CI_upper = UCL)%>%
  pivot_wider(names_from = "combination", values_from = "EMM")


# 5. Confidence in Knowledge =====================================================
# Interaction model
Mconf<-lm(pol_confidence ~ 
            age + education_num + sex_fem  + ideology + # demographics
            Analysis+
            InterestedNum+
            InterestedNum*pos_id_mean*neg_id_mean , # 3 way interaction
          data = meta_std) # data frame with only interested 

# Create interaction data frame
inter_conf <- emmip(Mconf,neg_id_mean~pos_id_mean~InterestedNum,at=list, CIs=TRUE, PIs=TRUE, plotit = FALSE)
inter_conf$combination<-paste(inter_conf$xvar,inter_conf$tvar, sep = " ") # combine conditions

#inter_conf_keep<-inter_conf%>%
#  dplyr::select(., combination,yvar)%>%
#  pivot_wider(names_from = "combination", values_from = "yvar")
#inter_conf_keep$DV<- "Confidence in knowledge (H2c)"

inter_conf_keep<-inter_conf%>% 
  mutate(DV = "Confidence in knowledge (H2c)") %>%
  dplyr::select(., combination,yvar, LCL, UCL, DV)%>% 
  rename(EMM = yvar, CI_lower = LCL, CI_upper = UCL)%>%
  pivot_wider(names_from = "combination", values_from = "EMM")

# 6. Political Knowledge ==========================================================
# Interaction model
Mknow<-lm(pol_knowledge ~ 
            age + education_num + sex_fem  + ideology + # demographics
            Analysis+
            InterestedNum+
            InterestedNum*pos_id_mean*neg_id_mean , # 3 way interaction
          data = meta_std) # data frame with only interested 

# Create interaction data frame
inter_know <- emmip(Mknow,neg_id_mean~pos_id_mean~InterestedNum,at=list, CIs=TRUE, PIs=TRUE, plotit = FALSE)
inter_know$combination<-paste(inter_know$xvar,inter_know$tvar, sep = " ") # combine conditions

#inter_know_keep<-inter_know%>%
#  dplyr::select(., combination,yvar)%>%
#  pivot_wider(names_from = "combination", values_from = "yvar")
#inter_know_keep$DV<- "Political knowledge (H4a; H4c)"

inter_know_keep<-inter_know%>% 
  mutate(DV = "Political knowledge (H4a; H4c)") %>%
  dplyr::select(., combination,yvar, LCL, UCL, DV)%>% 
  rename(EMM = yvar, CI_lower = LCL, CI_upper = UCL)%>%
  pivot_wider(names_from = "combination", values_from = "EMM")

# Regression table with all six models ----
stargazer(Mactiv, Meff, Mnews, Mopen, Mconf, Mknow,
          type="latex", digits = 2, digits.extra = 0, summary = F, style = "apsr",omit.stat = "f")


